/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.acmwustl.bubble.controllers;

import org.acmwustl.bubble.gui.ValidatePaymentFrame;
import org.acmwustl.bubble.gui.ConfirmPaymentFrame;
import org.acmwustl.bubble.gui.PaymentFrame;
import org.acmwustl.bubble.gui.PostPaymentFrame;
import org.acmwustl.bubble.logic.ConnectionManager;

/**
 *
 * @author tyler
 */
public class PaymentController {

    private PaymentFrame myParent;

    public PaymentController(PaymentFrame parent) {
        myParent = parent;
    }

    public void confirmPayment(ConfirmPaymentFrame aThis, String keyIDCode, int amount) {
        aThis.dispose();
        ValidatePaymentFrame vpf = new ValidatePaymentFrame(keyIDCode, amount, this);
        vpf.setVisible(true);
    }

    public boolean authorizePayment(String officerIDCode, String paymentIDCode, int amount) {
        ConnectionManager cm = ConnectionManager.getInstance();
        if(cm.isOfficer(officerIDCode)) {
            cm.updateBalanceInCents(paymentIDCode,amount + cm.getBalanceInCents(paymentIDCode));
            PostPaymentFrame ppf = new PostPaymentFrame(cm.getBalanceInCents(paymentIDCode));
            ppf.setVisible(true);
            return true;
        }
        else
            return false;
    }

    public void submitPayment(int paymentAmt) {
        myParent.dispose();
        ConfirmPaymentFrame cpf = new ConfirmPaymentFrame(paymentAmt, this);
        cpf.setVisible(true);
    }
}
